package com.gxa.controller.zhy;

import com.gxa.common.R;
import com.gxa.pojo.Performance;
import com.gxa.pojo.Permission;
import com.gxa.pojo.Role;
import com.gxa.pojo.zhy.EditPermission;
import com.gxa.pojo.zhy.Paging;
import com.gxa.pojo.zhy.Pr;
import com.gxa.service.RoleAuthorizationService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 赵贺益
 * Date: 2021/12/04 10:35
 * Description:
 * Version: V1.0
 */

@Controller
@Api(value ="" ,tags = "系统管理模块接口（角色权限）3 ")
@RequestMapping("/system")
public class RoleAuthorizationController {
    @Autowired
    private RoleAuthorizationService roleAuthorizationService;
    /**
     * 根据当前页码数和每页显示的数量查询所有的角色以及相关信息
     * @param currentPage
     * @param pageSize
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/queryAllRoles",method = RequestMethod.GET)
    @ApiOperation(value = "请求获取所有角色的接口（默认currentPage=1（当前页码），pageSize=10（每页显示的数据））",notes = "返回的是一个R对象,R中的data中有List<Role>(集合对象)，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前的页码数" ,required = false,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示的条数",required =false,paramType ="query")

    })

    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "查询失败"),
            @ApiResponse(code = 500,message = "后台服务错误")

    })
    public R queryAllRoles(@RequestParam(value = "currentPage",defaultValue = "1") Integer currentPage, @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize){

        R r=roleAuthorizationService.queryAllRoles(currentPage,pageSize);
        return r;

    }


    /**
     * 模糊搜索显示所有的角色
     * @param
     * @param
     * @param
     * @return
     */
    @ResponseBody
//    @RequestMapping(value ="/querySearchRolesbyKeyword",method = RequestMethod.POST)
    @RequestMapping(value ="/querySearchRolesbyKeyword",method = RequestMethod.GET)
    @ApiOperation(value = "请求获取所有角色的接口(模糊搜索显示所有的角色)（默认currentPage=1（当前页码），pageSize=10（每页显示的数据））",notes = "返回的是一个R对象,R对象中的data中有List<Role>(集合对象)，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "currentPage",value = "当前的页码数" ,required = false,paramType = "query"),
            @ApiImplicitParam(name = "pageSize",value = "每页显示的条数",required =false,paramType ="query"),
            @ApiImplicitParam(name = "keyword",value = "搜索框输入的关键字",required =false,paramType ="query")
    })

//    public R querySearchRolesbyKeyword(@RequestBody@ApiParam Paging paging){
    public R querySearchRolesbyKeyword(Integer currentPage,Integer pageSize,String message){
//         R r=roleAuthorizationService.querySearchRolesbyKeyword(paging);
         R r=roleAuthorizationService.querySearchRolesbyKeyword(currentPage,pageSize,message);
        return r;

    }


    /**
     * 根据角色id(role_id)删除角色
     * @param role_id
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/deleteRoleByRole_id",method = RequestMethod.GET)
    @ApiOperation(value = "删除指定角色的接口",notes = "返回的是一个对象R，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",value = "当前行数据的id（role_id）" ,required = true,paramType = "query")
    })

    @ApiResponses({
            @ApiResponse(code=200,message = "删除成功"),
            @ApiResponse(code=504,message = "删除失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })

    public R deleteRoleByRole_id(Integer role_id ){

        R r=roleAuthorizationService.deleteRoleByRole_id(role_id);
        return r;
    }


    /**
     * 添加角色
     * @param
     * @param
     * @return
     */

    @ResponseBody
    @RequestMapping(value ="/addRole",method = RequestMethod.POST)
    @ApiOperation(value = "添加角色的接口",notes = "返回的是一个对象R，对象结构如下",httpMethod = "POST", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_name",value = "角色名称" ,required = true,paramType = "query"),
            @ApiImplicitParam(name = "role_describe",value = "角色描述" ,required = true,paramType = "query")
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "添加成功"),
            @ApiResponse(code=504,message = "添加失败,该角色已经存在"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public  R addRole(@RequestBody @ApiParam Role role){
        String role_name=role.getRole_name();
        String role_describe=role.getRole_describe();
        System.out.println(role_name);
        System.out.println(role_describe);

        R r=roleAuthorizationService.addRole(role_name,role_describe);
        return r;
    }


    /**
     * 根据角色id请求显示其对应的所有的权限
     * @param role_id
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/queryAllRolesByRole_id",method = RequestMethod.GET)
    @ApiOperation(value = "根据角色id请求显示其对应的所有的权限接口",notes = "返回的是一个对象R，对象结构如下",httpMethod = "GET", response =R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "role_id",value = "角色id" ,required = true,paramType = "query"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "查询成功"),
            @ApiResponse(code=504,message = "该角色无权限"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public R queryAllRolesByRole_id(Integer role_id){
          R r=roleAuthorizationService.queryAllRolesByRole_id(role_id);
          return  r;
    }

    /**
     * 修改角色信息（名字，描述）
     * @param role
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/updateRolesInformationbyRoleId",method = RequestMethod.POST)
    @ApiOperation(value = "根据角色id修改角色信息（名字，描述）",notes = "返回的是一个对象R，对象结构如下",httpMethod = "POST", response =R.class)
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "role_id",value = "角色id" ,required = true,paramType = "query"),
//            @ApiImplicitParam(name = "role_name",value = "角色名字" ,required = true,paramType = "query"),
//            @ApiImplicitParam(name = "role_describe",value = "角色描述" ,required = true,paramType = "query"),
//    })
    @ApiResponses({
            @ApiResponse(code=200,message = "修改成功"),
            @ApiResponse(code=504,message = "修改失败"),
            @ApiResponse(code = 500,message = "后台服务错误")
    })
    public  R updateRolesInformationbyRoleId(@RequestBody @ApiParam Role role){
        R r=roleAuthorizationService.updateRolesInformationbyRoleId(role);
        return r;

    }

    /**
     * 根据角色id修改角色对应的权力信息(改中间表)
     * @param
     * @return
     */
    @ResponseBody
    @RequestMapping(value ="/updatePermissionByRoleId",method = RequestMethod.POST)
    @ApiOperation(value = "根据角色id修改角色对应的权力信息（",notes = "返回的是一个对象R，对象结构如下",httpMethod = "POST", response =R.class)
    @ApiResponses({
            @ApiResponse(code=200,message = "修改成功"),
            @ApiResponse(code=504,message = "不可提交空的权限"),
            @ApiResponse(code = 500,message = "服务器错误，删除失败")
    })
    public  R updatePermissionByRoleId(@RequestBody @ApiParam EditPermission editPermission){
        System.out.println("1111111111");
        System.out.println(editPermission);
        R r=roleAuthorizationService.updatePermissionByRoleId(editPermission);
        return r;

    }




}
